<div class="container">
  <div fxLayout="row" fxLayoutAlign="space-between center">
    <div class="title-desc">
      <h2>External Service</h2>
      <span>The saved authentication data for an external service such as GitHub or Azure. (<a href="https://docs.opencatapult.net/home/concept#external-service-connection" target="_blank">more...</a>)</span>
    </div>
    <div class="action-buttons">
      <button mat-raised-button (click)="onNewExternalServiceClick()">New External Service</button>
    </div>
  </div>

<app-loading-spinner *ngIf="loading"></app-loading-spinner>

<div *ngIf="!loading">
  <div class="no-records" *ngIf="externalServices?.length <= 0">
    No External services Found
  </div>

  <table mat-table [dataSource]="externalServices" matSort *ngIf="externalServices?.length > 0" class="mat-elevation-z8">

    <!--- Note that these columns can be defined in any order.
          The actual rendered columns are set as a property on the row definition" -->

    <!-- name Column -->
    <ng-container matColumnDef="name">
      <th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
      <td mat-cell *matCellDef="let element"> {{element.name}} </td>
    </ng-container>

    <!-- description Column -->
    <ng-container matColumnDef="description">
      <th mat-header-cell *matHeaderCellDef mat-sort-header> Description </th>
      <td mat-cell *matCellDef="let element"> <div class="description-col">{{element.description}}</div> </td>
    </ng-container>

    <!-- externalServiceTypeName Column -->
    <ng-container matColumnDef="externalServiceTypeName">
      <th mat-header-cell *matHeaderCellDef mat-sort-header appHelpElement="ExternalService" subSection="External Service Type"> Type </th>
      <td mat-cell *matCellDef="let element"> {{element.externalServiceTypeName}} </td>
    </ng-container>

    <!-- externalServiceTypeName Column -->
    <ng-container matColumnDef="isGlobal">
      <th mat-header-cell *matHeaderCellDef mat-sort-header> Allow global access? </th>
      <td mat-cell *matCellDef="let element"> {{element.isGlobal ? 'Yes' : 'No'}} </td>
    </ng-container>
    <!-- Action Column -->
    <ng-container matColumnDef="actions">
      <th mat-header-cell *matHeaderCellDef> </th>
      <td mat-cell *matCellDef="let element" class="service-buttons">
        <button mat-icon-button (click)="onInfoClick(element)">
          <mat-icon>info</mat-icon>
        </button>
        <button mat-icon-button (click)="onDeleteClick(element)">
          <mat-icon>delete</mat-icon>
        </button>
      </td>
    </ng-container>

    <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
  </table>
</div>
</div>
